package com.example.yangyang.recylerviewtest125yy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;//RecyclerView控件
    //RecyclerView控件布局管理
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;//Recycle的适配器

    private List<ArticleBean> list=null;//保存数据
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
    }
private void initRecyclerView(){
    recyclerView=( RecyclerView)findViewById(R.id.recyclerview);//创建默认的线性布局
    layoutManager=new LinearLayoutManager(this);//设置布局管理器
    recyclerView.setLayoutManager(layoutManager);//固定每个item高度，可以提高性能
    recyclerView.setHasFixedSize(true);
    list=getDate();
    myAdapter=new MyAdapter(this);
    myAdapter.setList(list);
    recyclerView.setAdapter(myAdapter);

}
private List<ArticleBean> getDate(){
     List<ArticleBean> list=new ArrayList<ArticleBean>();
    ArticleBean articleBean;
    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题1");
    articleBean.setDescription("描述1");
    articleBean.setTime("2017-4-1");
    articleBean.setImgid((R.drawable.f1));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题2");
    articleBean.setDescription("描述2");
    articleBean.setTime("2017-4-2");
    articleBean.setImgid((R.drawable.f2));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题3");
    articleBean.setDescription("描述3");
    articleBean.setTime("2017-4-3");
    articleBean.setImgid((R.drawable.f3));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题4");
    articleBean.setDescription("描述4");
    articleBean.setTime("2017-4-4");
    articleBean.setImgid((R.drawable.f4));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题5");
    articleBean.setDescription("描述5");
    articleBean.setTime("2017-4-5");
    articleBean.setImgid((R.drawable.f5));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题1");
    articleBean.setDescription("描述1");
    articleBean.setTime("2017-4-1");
    articleBean.setImgid((R.drawable.f1));
    list.add(articleBean);

    articleBean=new ArticleBean();
    articleBean.setArticleId(1);
    articleBean.setTitle("标题6");
    articleBean.setDescription("描述6");
    articleBean.setTime("2017-4-6");
    articleBean.setImgid((R.drawable.f6));
    list.add(articleBean);
    return list;
}

}